<template>
  <div>

    <!-- 承包商弹出框 -->
  <el-dialog :title="title" :visible.sync="visible" width="800px" append-to-body @close="handleClose">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单位编码" prop="companyCode">
        <el-input
          v-model="queryParams.companyCode"
          placeholder="请输入单位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位简称" prop="companyAbbr">
        <el-input
          v-model="queryParams.companyAbbr"
          placeholder="请输入单位简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="contractorList"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="extSysId" />
      <el-table-column label="单位编码" align="center" prop="companyCode" />
      <el-table-column label="单位名称" align="center" prop="companyName" />
      <el-table-column label="单位简称" align="center" prop="companyAbbr" />
      <el-table-column label="单位类型" align="center" prop="companyType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.zhjj_unit_type"
            :value="scope.row.companyType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="企业社会统一信用代码"
        width="160"
        align="center"
        prop="unifiedSocialCreditCode"
      />
      <el-table-column label="联系人" align="center" prop="contactPerson" />
      <el-table-column label="联系电话" align="center" prop="contactPhone" />
      <el-table-column label="单位状态" align="center" prop="unitState">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.zhjj_unit_status"
            :value="scope.row.unitState"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="资质等级"
        align="center"
        prop="qualificationLevel"
      />
      <el-table-column label="注册资金" align="center" prop="registerCapital" />
      <el-table-column label="注册地址" align="center" prop="registerAddress" />
      <el-table-column label="主要业绩" align="center" prop="achievement" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        width="120"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-thumb"
            @click="handleSelect(scope.row)"
            v-hasPermi="['zhjj:contractor:edit']"
            >选择</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
  </div>

</template>

<script>
import { listContractor, getContractor } from "@/api/zhjj/contractor";
export default {
  name: "ContractorDialog",
  dicts: ['zhjj_unit_type', 'zhjj_unit_status'],
  props: {
    // 弹出层是否显示，由父组件控制
    visible: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 承包商表格数据
      contractorList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyCode: null,
        companyName: null,
        companyAbbr: null,
        companyType: null,
        unifiedSocialCreditCode: null,
        contactPerson: null,
        contactPhone: null,
        unitState: null,
        qualificationLevel: null,
        registerCapital: null,
        registerAddress: null,
        achievement: null,
        createBy: null,
      },
    };
  },
  watch: {
    // 监听 visible 变化，重置表单
    visible(newVal) {
      if (newVal) {
        this.getList();
      }
    },
  },
  methods: {
    /** 查询承包商列表 */
    getList() {
      this.loading = true;
      listContractor(this.queryParams).then(response => {
        this.contractorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.$emit("update:visible", false);
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        extSysId: null,
        companyCode: null,
        companyName: null,
        companyAbbr: null,
        companyType: null,
        unifiedSocialCreditCode: null,
        contactPerson: null,
        contactPhone: null,
        unitState: null,
        qualificationLevel: null,
        registerCapital: null,
        registerAddress: null,
        achievement: null,
        remark: null,
        createTime: null,
        updateTime: null,
        delFlag: null,
        createBy: null,
        updateBy: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 选择按钮操作 */
    handleSelect(row) {
      // 选中行数据，传递给父组件
      this.$emit("selectData", row);
      // 关闭弹窗
      this.handleClose();
    },
    /** 关闭弹窗时触发 */
    handleClose() {
      this.$emit("update:visible", false);
      this.reset();
    },
  },
};
</script>
